package com.homedo.microservice.distributed.id.service.remote.api.impl;

import com.google.common.collect.Lists;
import com.homedo.microservice.distributed.id.service.api.IGenerateNoServiceRemote;
import com.homedo.microservice.distributed.id.service.service.LeafAllocExtraNoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class GenerateNoServiceRemoteImpl implements IGenerateNoServiceRemote {

    private static final Logger _LOGGER = LoggerFactory.getLogger(GenerateNoServiceRemoteImpl.class);

    @Autowired
    private LeafAllocExtraNoService leafAllocExtraNoService;

    @Override
    public Object generateNo(@PathVariable("bizCode") String bizCode, Integer fetchSize) {

        if (fetchSize == null || fetchSize < 2) {
            return leafAllocExtraNoService.generateNo(bizCode);
        }
        List<String> nos = Lists.newArrayList();
        for (int i = 0; i < fetchSize; i++) {
            nos.add(leafAllocExtraNoService.generateNo(bizCode));
        }
        return nos;
    }
}
